from myro import *
#adsfasdfsad
initialize("COM40")

def getObstacles():
    return [getObstacle(x) for x in range(3)]

#start by going forward

deltaX=[]

while 1:
    if sum(getObstacles())>1000:
        stop()
        break
    forward(0.8, 1)

#detects obstacle, start turning right
turnRight(0.5, 1.6)
forward(1,1.5)
deltaX.append([1,3])

while 1:    
    turnLeft(0.5, 1.6)

    a=[]
    for i in range(6):     
        a+=getObstacles()
        wait(0.2)
    
    if sum(a)<400:
        print a
        stop()
        break

    turnRight(0.5, 1.6)
    forward(1, 1.5)
    deltaX.append([1,1.5])    

#goes forward a minimum distance to move past the obstacle
forward(1,3)

#turns left and checks if it passed the obstacle successfully
while 1:
    turnLeft(0.5, 1.6)
    

    a=[]
    for i in range(6):     
        a+=getObstacles()
        time.sleep(0.2)
    
    if sum(a)<400:
        print a
        stop()
        break

    turnRight(0.5, 1.6)
    forward(1, 1)
        

for speed, time in deltaX:
    forward(speed, time)
    stop()

turnRight(0.5,1.6)
forward()
    





